import React from 'react';

class Clock extends React.Component {
    constructor(props) {
        super(props);
        this.state = { date: new Date() };

        this.clickHandler2 = this.clickHandler2.bind(this);
    }

    tick() {
        this.setState({
            date: new Date()
        });
    }

    componentDidMount() {
        this.timerID = setInterval(
            () => this.tick(),
            1000
        );
    }

    componentWillUnmount() {
        clearInterval(this.timerID);
    }

    clickHandler = () => {
        alert(11)
    }

    clickHandler2() {
        alert(22)
    }

    render() {
        return (
            <div onClick={this.clickHandler2}>{this.state.date.toLocaleTimeString()}</div>
        );
    }
}

class Home extends React.Component {
    render() {
        return (
            <Clock />
        )
    }
}

export default Home;